/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.ContentResource;
import com.blandware.atleap.model.core.ResourceData;
import com.blandware.atleap.persistence.exception.DeleteException;

import java.util.List;

/**
 * <p>DAO for content resource</p>
 * <p><a href="ContentResourceDAO.java.html"><i>View Source</i></a></p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.12 $ $Date: 2008/01/14 10:59:47 $
 */
public interface ContentResourceDAO extends DAO {

	// ~ CRUD Methods ================================================================

	/**
	 * Creates new content resource
	 *
	 * @param contentResource Object that represents what resource must be created
     * @param resourceData Object that represents binary data for new resource
	 * @return ID of created content resource
	 */
	public Long createContentResource(ContentResource contentResource, ResourceData resourceData);

	/**
	 * Retrieves content resource with specified ID
	 *
	 * @param contentResourceId ID to search by
	 * @return Content resource or null if no content resource with specified ID exists in database
	 */
	public ContentResource retrieveContentResource(Long contentResourceId);

	/**
	 * Updates content resource
	 *
	 * @param contentResource Content resource to update
     * @param resourceData Object that represents binary data for updated
     * resource
	 */
	public void updateContentResource(ContentResource contentResource, ResourceData resourceData);

	/**
	 * Deletes content resource
	 *
	 * @param contentResource Resource to delete
	 * @throws DeleteException if content resource cannot be deleted
	 */
	public void deleteContentResource(ContentResource contentResource) throws DeleteException;

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of content resources.
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of resources
	 */
	public PartialCollection listContentResources(QueryInfo queryInfo);

	/**
	 * Retrieves no more than number of elements, specified in queryInfo's <code>limit</code> field.
	 *
	 * @param queryInfo Object that contains list of user roles and number of elements to return.
     * All of these are passed as query parameters: list of roles under key 'roles'.
     * Only resources that are allowed to view for some of the given roles are returned.
	 * @return List of content resources that correspond to <code>queryInfo</code>
	 */
	public List getLastContentResources(QueryInfo queryInfo);

    /**
	 * Searches for duplicates. Returns true if there is one or more resources with another ID, but which
	 * have same values from some set (e.g. uri)
	 *
	 * @param contentResource Resource to find duplicates for
	 * @return whether this content resource has duplicates
	 */
	public boolean hasDuplicates(ContentResource contentResource);

    /**
     * Removes associations of a ContentResource with other objects (usually,
     * this is made before deletion). Here, non-cascadable associations should
     * be removed.
     *
     * @param contentResource resource from which to remove associations
     */
    public void removeAssociations(ContentResource contentResource);

	// ~ Finders ================================================================

	/**
	 * Finds content resource by URI
	 *
	 * @param uri URI of resource to search by
	 * @return Content resource or null if nothing was found
	 */
	public ContentResource findContentResourceByUri(String uri);
}
